From 1ab2675b0ce39e5a42dd8f11826c66e045d26a52 Mon Sep 17 00:00:00 2001 From: Keir Fraser Date: Tue, 29 Jan 2008 15:15:51 +0000 Subject: [PATCH] xend: Obey localtime config option for HVM guests as well as PV guests. Signed-off-by: Keir Fraser --- tools/python/xen/lowlevel/xc/xc.c | 19 +++++-------------- tools/python/xen/xend/XendDomainInfo.py | 10 +++++++--- tools/python/xen/xend/image.py | 6 ++++++ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tools/python/xen/lowlevel/xc/xc.c b/tools/python/xen/lowlevel/xc/xc.c index f766d28e77..425ed7b0fe 100644 --- a/tools/python/xen/lowlevel/xc/xc.c +++ b/tools/python/xen/lowlevel/xc/xc.c @@ -1155,23 +1155,13 @@ static PyObject *pyxc_domain_iomem_permission(PyObject *self, static PyObject *pyxc_domain_set_time_offset(XcObject *self, PyObject *args) { uint32_t dom; - int32_t time_offset_seconds; - time_t calendar_time; - struct tm local_time; - struct tm utc_time; + int32_t offset; - if (!PyArg_ParseTuple(args, "i", &dom)) + if (!PyArg_ParseTuple(args, "ii", &dom, &offset)) return NULL; - calendar_time = time(NULL); - localtime_r(&calendar_time, &local_time); - gmtime_r(&calendar_time, &utc_time); - /* set up to get calendar time based on utc_time, with local dst setting */ - utc_time.tm_isdst = local_time.tm_isdst; - time_offset_seconds = (int32_t)difftime(calendar_time, mktime(&utc_time)); - - if (xc_domain_set_time_offset(self->xc_handle, dom, time_offset_seconds) != 0) - return NULL; + if (xc_domain_set_time_offset(self->xc_handle, dom, offset) != 0) + return pyxc_error_to_exception(); Py_INCREF(zero); return zero; @@ -1620,6 +1610,7 @@ static PyMethodDef pyxc_methods[] = { METH_VARARGS, "\n" "Set a domain's time offset to Dom0's localtime\n" " dom [int]: Domain whose time offset is being set.\n" + " offset [int]: Time offset from UTC in seconds.\n" "Returns: [int] 0 on success; -1 on error.\n" }, { "domain_send_trigger", diff --git a/tools/python/xen/xend/XendDomainInfo.py b/tools/python/xen/xend/XendDomainInfo.py index 0f866f02a6..ca3083bae2 100644 --- a/tools/python/xen/xend/XendDomainInfo.py +++ b/tools/python/xen/xend/XendDomainInfo.py @@ -1733,10 +1733,14 @@ class XendDomainInfo: self._configureBootloader() try: - self.image = image.create(self, self.info) - if self.info['platform'].get('localtime', 0): - xc.domain_set_time_offset(self.domid) + t = time.time() + loc = time.localtime(t) + utc = time.gmtime(t) + timeoffset = int(time.mktime(loc) - time.mktime(utc)) + self.info['platform']['rtc_timeoffset'] = timeoffset + + self.image = image.create(self, self.info) xc.domain_setcpuweight(self.domid, \ self.info['vcpus_params']['weight']) diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py index 793c2b9aa8..80252345c1 100644 --- a/tools/python/xen/xend/image.py +++ b/tools/python/xen/xend/image.py @@ -346,6 +346,12 @@ class LinuxImageHandler(ImageHandler): flags = 0 vhpt = 0 + def configure(self, vmConfig): + ImageHandler.configure(self, vmConfig) + rtc_timeoffset = vmConfig['platform'].get('rtc_timeoffset') + if rtc_timeoffset is not None: + xc.domain_set_time_offset(self.vm.getDomid(), rtc_timeoffset) + def buildDomain(self): store_evtchn = self.vm.getStorePort() console_evtchn = self.vm.getConsolePort() -- 2.30.2